var P1 = function (game) {

  this.create = function () {
    ClosePage(game,'1_0','1','1_r','1_w');

    function Page(game,cbg,mbg,rbg,wbg){
      var flag=[0,0];
      var container=game.add.sprite(0,0,'');
      var bg = game.add.sprite(0, 0, mbg);
      container.addChild(bg);
      var Lbtn,Rbtn;

      Lbtn=game.add.button(850, 220, 'ok_0', actionOnClick, this, 2, 1, 0);
      Lbtn.data=0;
      Rbtn=game.add.button(1050, 220, 'no_0', actionOnClick, this, 2, 1, 0);
      Rbtn.data=1;


      var graphics = game.add.graphics(0, 0);

      function actionOnClick (arg) {
        flag.forEach(function (item,i) {
          if(i!=arg.data){
            flag[i]=0;
          }
        })
        flag[arg.data] = flag[arg.data]===0 ? 1: 0;
        Lbtn.loadTexture('ok_'+flag[0]);
        Rbtn.loadTexture('no_'+flag[1]);
      }
      var submit = game.add.button(1250, 625, imgs['button'], onSubmit, game, 2, 1, 0);
      submit.width = 160;
      submit.height = 55;
      container.addChild(submit);

      function onSubmit() {
        container.destroy();
        if(flag.join('_') ==='1_0'){
          RightPage(game,cbg,mbg,rbg,wbg);
        }else{
          WrongPage(game,cbg,mbg,rbg,wbg);
        }
      }
    }
    function ClosePage(game,cbg,mbg,rbg,wbg) {
      var container=game.add.sprite(0,0,'');
      var close = game.add.button(0, 0, cbg, onClose, this, 2, 1, 0);
      container.addChild(close);
      function onClose() {
        container.destroy();
        Page(game,cbg,mbg,rbg,wbg);
      }
    }


    function WrongPage(game,cbg,mbg,rbg,wbg){
      var container=game.add.sprite(0,0,'');

      var bg = game.add.image(0, 0, wbg);
      container.addChild(bg);
      var retry = game.add.button(1250, 625, imgs['button'], onClick, this, 2, 1, 0);
      retry.name = 'retry';
      retry.width = 160;
      retry.height = 55;
      container.addChild(retry);

      function onClick(arg) {
          container.destroy();
          Page(game, cbg, mbg, rbg, wbg);
      }
    }
    function RightPage(game,cbg,mbg,rbg,wbg){
      var container=game.add.sprite(0,0,'');

      var bg = game.add.image(0, 0, rbg);
      container.addChild(bg);
      var next = game.add.button(1250, 625, imgs['button'], onClick, game, 2, 1, 0);
      next.width = 160;
      next.height = 55;
      container.addChild(next);

      function onClick() {
        game.goState('next');
      }
    }
  }

}




